
import { getToken } from '@/utils/auth';
import { url } from 'inspector';
import { createWebHashHistory, createRouter } from 'vue-router'

const history = createWebHashHistory()
const router = createRouter({
	history,
	routes: [{
		path: '/',
		redirect: '/index'
	},
	{
		path: '/index',
		component: () => import('@/views/index/index.vue'),
		children: [{
			path: '/index',
			// redirect: '/index/data-preview',
			redirect: '/index/total-preview',
		},
		{
			path: 'data-preview',
			component: () => import('@/views/dataPreview/index.vue'),
			meta: {
				nav: true,
				title: '平台企业协同共治'
			},
		}, {
			path: 'platform',
			component: () => import('@/views/platform/platform.vue'),
			meta: {
				nav: true,
				title: '平台企业协同共治'
			},
		}, {
			path: 'total-preview',
			component: () => import('@/views/totalPreview/index.vue'),
			meta: {
				nav: true,
				title: '平台企业协同共治'
			},
		}, {
			path: 'todo',
			component: () => import('@/views/todo/index.vue'),
			meta: {
				nav: true,
				title: '工作待办'
			},
		}, {
			path: '/workbench',
			component: () => import('@/views/workbench/index.vue'),
			meta: {
				nav: true,
				title: '工作台'
			},
		},
		{
			path: '/user',
			meta: {
				nav: true,
				title: '我的'
			},
			component: () => import('@/views/center/index.vue')
		}]
	}, {
		path: '/todo/taskapproval',
		component: () => import('@/views/todo/todoTaskApproval/index.vue'),
		meta: {
			nav: true,
			title: '任务审批'
		},
	}, {
		path: '/todo/taskplatfromsend',
		component: () => import('@/views/todo/todoTaskPlatfromSend/index.vue'),
		meta: {
			nav: true,
			title: '发送平台'
		},
	}, {
		path: '/todo/taskplatfromadd',
		component: () => import('@/views/todo/todoTaskPlatfromAdd/index.vue'),
		meta: {
			nav: true,
			title: '新增平台'
		},
	}, {
		path: '/todo/taskapprovalprocess',
		component: () => import('@/views/todo/todoTaskApprovalProcess/index.vue'),
		meta: {
			nav: true,
			title: '审批流程'
		},
	}, {
		path: '/todo/taskapprovalsend',
		component: () => import('@/views/todo/todoTaskApprovalSend/index.vue'),
		meta: {
			nav: true,
			title: '审批发送'
		},
	}, {
		path: '/todo/taskapprovalsendback',
		component: () => import('@/views/todo/todoTaskApprovalSendBack/index.vue'),
		meta: {
			nav: true,
			title: '审批退回'
		},
	}, {
		path: '/',
		meta: {
			nav: true
		},
		component: () => import('@/views/workbench/index.vue')
	},
	{
		path: '/orderTask',
		meta: {
			nav: true,
			title: '指令任务'
		},
		component: () => import('@/views/workbench/orderTask/index.vue'),
		children: [{
			path: 'targetPlatform',
			meta: {
				nav: true,
				title: '新增平台'
			},
			component: () => import('@/views/workbench/target/index.vue')
		},
		{
			path: 'edit',
			meta: {
				nav: true,
				title: '模板编辑'
			},
			component: () => import('@/views/workbench/model/index.vue'),
			children: [{
				path: 'option',
				meta: {
					nav: true,
					title: '模板编辑'
				},
				component: () => import('@/views/workbench/model/type/index.vue')
			}
			]
		}]
	},
	{
		path: '/compliance',
		meta: {
			nav: true,
			title: '合规提示'
		},
		component: () => import('@/views/workbench/compliance/index.vue'),
		children: [{
			path: 'targetPlatform',
			meta: {
				nav: true,
				title: '新增平台'
			},
			component: () => import('@/views/workbench/target/index.vue')
		},
		{
			path: 'edit',
			meta: {
				nav: true,
				title: '模板编辑'
			},
			component: () => import('@/views/workbench/model/index.vue'),
			children: [{
				path: 'option',
				meta: {
					nav: true,
					title: '模板编辑'
				},
				component: () => import('@/views/workbench/model/type/index.vue')
			}
			]
		}]
	},
	{
		path: '/statistics',
		meta: {
			nav: true,
			title: '统计报表'
		},
		component: () => import('@/views/workbench/statistics/index.vue'),
		children:[{
			path: 'targetPlatform',
			meta: {
				nav: true,
				title: '新增平台'
			},
			component: () => import('@/views/workbench/target/index.vue')
		},{
			path: 'edit',
			meta: {
				nav: true,
				title: '模板编辑'
			},
			component: () => import('@/views/workbench/model/index.vue'),
			children: [{
				path: 'option',
				meta: {
					nav: true,
					title: '模板编辑'
				},
				component: () => import('@/views/workbench/model/type/index.vue')
			}
			]
		}]
	},
	{
		path: '/report',
		meta: {
			nav: true,
			title: '主动报告'
		},
		component: () => import('@/views/workbench/report/index.vue')
	},
	{
		path: '/banned',
		meta: {
			nav: true,
			title: '禁售商品词库'
		},
		component: () => import('@/views/workbench/banned/index.vue')
	},
	{
		path: '/policy',
		meta: {
			nav: true,
			title: '政策查询'
		},
		component: () => import('@/views/workbench/policy/index.vue')
	},
	{
		path: '/policy/detail',
		meta: {
			nav: true,
			title: '政策查询'
		},
		component: () => import('@/views/workbench/policy/detail/index.vue'),
	},
	{
		path: '/law',
		meta: {
			nav: true,
			title: '法律法规查询'
		},
		component: () => import('@/views/workbench/law/index.vue')
	},
	{
		path: '/law/detail',
		meta: {
			nav: true,
			title: '法律法规查询'
		},
		component: () => import('@/views/workbench/law/detail/index.vue')
	},
	{
		path: '/department',
		meta: {
			nav: true,
			title: '部门与用户统计'
		},
		component: () => import('@/views/workbench/department/index.vue')
	},
	{
		path: '/taskpreview',
		meta: {
			nav: true,
			title: '任务查看'
		},
		component: () => import('@/views/taskPreview/index.vue')
	},
	{
		path: '/taskpreview/taskapproval',
		meta: {
			nav: true,
			title: '任务详情'
		},
		component: () => import('@/views/taskPreview/taskApproval/index.vue')
	},
	{
		path: '/taskpreview/taskapprovalprocess',
		meta: {
			nav: true,
			title: '任务流程'
		},
		component: () => import('@/views/taskPreview/taskApprovalProcess/index.vue')
	},
	{
		path: '/taskpreview/taskplatfrominfoprocess',
		meta: {
			nav: true,
			title: '时间线'
		},
		component: () => import('@/views/taskPreview/taskPlatfromInfoProcess/index.vue')
	},
	{
		path: '/taskpreview/taskplatfromsend',
		meta: {
			nav: true,
			title: '发送平台'
		},
		component: () => import('@/views/taskPreview/taskPlatfromSend/index.vue')
	},
	{
		path: '/taskpreview/taskplatfrominfo',
		meta: {
			nav: true,
			title: '平台信息'
		},
		component: () => import('@/views/taskPreview/taskPlatfromInfo/index.vue')
	},
	{
		path: '/reportpreview',
		meta: {
			nav: true,
			title: '上报查看',
		},
		component: () => import('@/views/reportPreview/index.vue')
	},
	{
		path: '/reportpreview/reportapprovalsendback',
		meta: {
			nav: true,
			title: '上报退回'
		},
		component: () => import('@/views/reportPreview/reportApprovalSendBack/index.vue')
	},
	{
		path: '/reportpreview/reportapprovalprocess',
		meta: {
			nav: true,
			title: '审批查看'
		},
		component: () => import('@/views/reportPreview/reportApprovalProcess/index.vue')
	},
	{
		path: '/reportpreview/reportapproval',
		meta: {
			nav: true,
			title: '上报查看'
		},
		component: () => import('@/views/reportPreview/reportApproval/index.vue')
	},
	{
		path: '/reportpreview/reportapprovalprocess',
		meta: {
			nav: true,
			title: '审批查看'
		},
		component: () => import('@/views/reportPreview/reportApprovalProcess/index.vue')
	},
	{
		path: '/reportpreview/reportplatfromsend',
		meta: {
			nav: true,
			title: '上报平台'
		},
		component: () => import('@/views/reportPreview/reportPlatfromSend/index.vue')
	},
	{
		path: '/reportpreview/reportplatfrominfo',
		meta: {
			nav: true,
			title: '平台详情'
		},
		component: () => import('@/views/reportPreview/reportPlatfromInfo/index.vue')
	},
	{
		path: '/taskcensus',
		meta: {
			nav: true,
			title: '任务统计'
		},
		component: () => import('@/views/taskCensus/index.vue')
	},
	{
		path: '/basiscensus',
		meta: {
			nav: true,
			title: '依据统计'
		},
		component: () => import('@/views/basisCensus/index.vue')
	},
	{
		path: '/demo',
		meta: {
			nav: true,
			title: '依据统计'
		},
		component: () => import('../demo.vue')
	}, {
		name: 'login',
		path: '/login',
		component: () => import('@/views/login/index.vue')
	},
	],
});

router.beforeEach((to, _from, next) => {
	const token = getToken()
	if (to.name === 'login') {
		next();
		return
	}
	if (token) {
		next();
	} else {
		router.push({ name: 'login' })
	}
})


// router.beforeEach((to, from, next) => {

// 	const path = 'http://192.168.0.104:5173/'
// 	let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1fc01e7a7775a0b3&redirect_uri=${path}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
// 	let code = getRequest(window.location.href.split("#")[0], "code") || "";

// 	// let appenid = localStorage.getItem("openId") || "";	// 有 openid 则不用再获取权限
// 	// if (!appenid) {
// 	if (!code) {
// 		window.location.href = url;
// 	} else {
// 		code = getRequest(window.location.href, "code");
// 		console.log("code", code);
// 		next()
// 		// 有 code 值，就做相应的操作。例如，登录需要携带 code ,返回具体的 openid,头像
// 	}
// 	// } else {
// 	// 	next();
// 	// }
// })
// // 判断是否有 code , 有 code 的值就返回
// const getRequest = (url: string, queryName: any): string => {
// 	url = url + "";
// 	let regstr = "/(\\?|\\&)" + queryName + "=([^\\&]+)/";
// 	let reg = eval(regstr);
// 	//eval可以将 regstr字符串转换为 正则表达式
// 	let result = url.match(reg);
// 	if (result && result[2]) {
// 		return result[2];
// 	}
// 	return ''
// }

export default router;